<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 控件数据控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\service\TemplateTodoService;
use common\service\WorkTimeRecordService;
use Exception;
use think\Request;
use think\Response;

class TemplateTodoController extends VerifyController
{
    /**
     * @var WorkTimeRecordService
     */
    private $templateTodoService;

    public function __construct()
    {
        parent::__construct();
        $this->templateTodoService = TemplateTodoService::getInstance();
    }

    /**
     * 添加
     * @param $request
     * @return Response
     */
    public function create($request)
    {
        $res = $this->templateTodoService->save($request->param()['data'] ?? []);
        return json(success_response('', $res));

    }

    /**
     * 更新
     * @param $request
     * @return Response
     * @throws Exception
     */
    public function update($request)
    {
        $res = $this->templateTodoService->save($request->param()['data'] ?? []);
        return json(success_response('', $res));
    }

    /**
     * filter删除
     * @param $request
     * @return Response
     * @throws \Throwable
     */
    public function delete($request)
    {
        $res = $this->templateTodoService->delete($request->param()['param']['filter'] ?? []);
        return json(success_response('', $res));
    }

    /**
     * 模板列表
     * @param Request $request
     * @return Response
     * @throws Exception
     */
    public function list(Request $request)
    {
        $res = $this->templateTodoService->list($request->param()['param']);
        return json(success_response('', $res));
    }

    /**
     * @param Request $request
     * @return Response
     * @throws Exception
     */
    public function getOne(Request $request)
    {
        $id = $request->param()['param']['filter']['id'] ?? 0;
        $res = $this->templateTodoService->getOne($id);
        return json(success_response('', $res));
    }



    /**
     * 获取关联交付列表
     * @param Request $request
     * @return Response
     */
    public function getFileList(Request $request)
    {
        $res = $this->templateTodoService->getTemplateTodoFileList($request->param()['param']['filter'] ?? []);
        return json(success_response('', $res));
    }

    /**
     * 获取开发模板下的提出阶段
     * @param Request $request
     * @return Response
     */
    public function getOpenTemplateTodoStageList(Request $request)
    {
        $param = $request->param()['param'];
        $page = $param['page'] ?? [1, C('default_page_total')];
        $res = $this->templateTodoService->getOpenTemplateTodoStageList($param['filter']['project_id'], $page);
        return json(success_response('', $res));
    }
}
